package a8;

public class Latitude {

	double lat;

	public Latitude(double degLatitude) {
		if (degLatitude > 90. || degLatitude < -90.)
			throw new IllegalArgumentException("Latitude out of range");
		this.lat = toRadians(degLatitude);
	}

	public Latitude(int deg, int min, double sec) {
		this(deg + min / 60. + sec / 3600.);
	}

	private static double toRadians(double degLatitude) {
		return degLatitude * Math.PI / 180.;
	}

	public double getDegLat() {
		return this.lat * 180. / Math.PI;
	}

	public String getDMSLat(double ddeg) {
		ddeg= lat;
		int deg = 0;
		int min = 0;
		double sec = 0;

		deg = (int) ddeg;
		min = (int) ((ddeg - deg) * 60);
		sec = ((ddeg - deg) * 60 - min) * 60;

		String time = String.format("%d\u00b0%d\'%.1f\"", deg, min, sec);
		return time;

	}

	public double getLat() {
		return lat;
	}
}